package com.glsc.ngateway.common.base.domain.mysql.gateway.platform.webfield;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

/**
 * @author zhengyr
 * @date 2024/1/29-12:47
 * 增删改查类表单属性配置（主表）
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Entity
@Where(clause = "deleted = 0")
@SQLDelete(sql = "update t_gw_table_form_web_field set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@SQLDeleteAll(sql = "update t_gw_table_form_web_field set deleted = UNIX_TIMESTAMP(NOW()) where id=?")
@Table(name = "t_gw_table_form_web_field", indexes = {@Index(name = "UK_HOST", columnList = "page_key, deleted", unique = true)})
public class TableFormWebField implements Serializable {

    @ApiModelProperty(value = "id")
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    @ApiModelProperty(value = "代表页面类型的type+id组合")
    private String ident;

    @ApiModelProperty(value = "是否需要新建父级路由")
    @Column(name = "is_parent_create", columnDefinition = "char(1) NOT NULL COMMENT '是否需要新建父级路由'")
    private String isParentCreate;

    @ApiModelProperty(value = "父级路由菜单权限--path")
    @Column(name = "router_location", columnDefinition = "VARCHAR(200) NOT NULL COMMENT '父级路由菜单权限--path'")
    @Builder.Default
    private String routerLocation="root";

    @ApiModelProperty(value = "页面中文名")
    @Column(name = "page_name", columnDefinition = "VARCHAR(50) NOT NULL COMMENT '页面中文名'")
    private String pageName;

    @ApiModelProperty(value = "页面英文名(唯一)")
    @Column(name = "page_key", columnDefinition = "VARCHAR(50) NOT NULL COMMENT '页面英文名'")
    private String pageKey;

    @ApiModelProperty(value = "唯一id列的英文名")
    @Column(name = "row_key", columnDefinition = "VARCHAR(50) NOT NULL default 'id' COMMENT '唯一id列的英文名'")
    @Builder.Default
    private String rowKey="id";

    @ApiModelProperty(value = "查询数据接口url")
    @Column(name = "search_api", columnDefinition = "VARCHAR(200) NOT NULL COMMENT '查询数据接口url'")
    private String searchApi;

    @ApiModelProperty(value = "新增数据接口url")
    @Column(name = "add_api", columnDefinition = "VARCHAR(200) COMMENT '新增数据接口url'")
    private String addApi;

    @ApiModelProperty(value = "修改数据接口url")
    @Column(name = "update_api", columnDefinition = "VARCHAR(200) COMMENT '修改数据接口url'")
    private String updateApi;

    @ApiModelProperty(value = "删除数据接口url")
    @Column(name = "delete_api", columnDefinition = "VARCHAR(200) COMMENT '删除数据接口url'")
    private String deleteApi;

    @ApiModelProperty(value = "上传数据接口url")
    @Column(name = "upload_api", columnDefinition = "VARCHAR(200) COMMENT '上传数据接口url'")
    private String uploadApi;

    @ApiModelProperty(value = "导出类型")
    @Column(name = "export_type", columnDefinition = "char(1) NOT NULL COMMENT '导出类型' ")
    private String exportType;

    @ApiModelProperty(value = "导出接口url")
    @Column(name = "export_api", columnDefinition = "VARCHAR(200) COMMENT '导出接口url'")
    private String exportApi;

    @Builder.Default
    @Column(name = "deleted", columnDefinition = "bigint NOT NULL default 0")
    private Long deleted = 0L;

    @Transient
    @ApiModelProperty(value = "字段配置列表")
    private List<WebFieldItem> fieldList;
}
